package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.BigcapService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.BigcapForm;
import com.youlai.boot.system.model.query.BigcapQuery;
import com.youlai.boot.system.model.vo.BigcapVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 大盘底表前端控制层
 *
 * @author xiheforever
 * @since 2025-05-11 22:39
 */
@Tag(name = "大盘底表接口")
@RestController
@RequestMapping("/api/v1/bigcap")
@RequiredArgsConstructor
public class BigcapController  {

    private final BigcapService bigcapService;

    @Operation(summary = "大盘底表分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:bigcap:query')")
    public PageResult<BigcapVO> getBigcapPage(BigcapQuery queryParams ) {
        IPage<BigcapVO> result = bigcapService.getBigcapPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增大盘底表")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:bigcap:add')")
    public Result<Void> saveBigcap(@RequestBody @Valid BigcapForm formData ) {
        boolean result = bigcapService.saveBigcap(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取大盘底表表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:bigcap:edit')")
    public Result<BigcapForm> getBigcapForm(
        @Parameter(description = "大盘底表ID") @PathVariable Long id
    ) {
        BigcapForm formData = bigcapService.getBigcapFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改大盘底表")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:bigcap:edit')")
    public Result<Void> updateBigcap(
            @Parameter(description = "大盘底表ID") @PathVariable Long id,
            @RequestBody @Validated BigcapForm formData
    ) {
        boolean result = bigcapService.updateBigcap(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除大盘底表")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:bigcap:delete')")
    public Result<Void> deleteBigcaps(
        @Parameter(description = "大盘底表ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = bigcapService.deleteBigcaps(ids);
        return Result.judge(result);
    }


}
